<?php
/**
 * Skyline :: Patterns & component framework
 * Copyright 2010-2011 Ian Unruh (Xerof3ar)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace Skyline\Structure\Map;

use Skyline\Comparator\ComparatorInterface;
use Skyline\Predicate\PredicateInterface;
use Skyline\Structure\ContainerInterface;

/**
 * A map is a collection of key-value entries
 * 
 * @author Ian Unruh (Xerof3ar) <ianunruh@gmail.com>
 * @since Class avaliable since release 1.0
 */
interface MapInterface extends ContainerInterface
{
	/**
	 * Returns true if a given key exists in this map
	 * 
	 * @param mixed $key
	 * @return bool
	 */
	public function containsKey($key);
	
	/**
	 * Returns true if a given value exists in this map
	 * 
	 * @param mixed $value
	 * @return bool
	 */
	public function containsValue($value);
	
	/**
	 * Returns the value associated with a given key (if any)
	 * 
	 * @param mixed $key
	 * @return mixed|null Returns null if key not in map
	 */
	public function get($key);
	
	/**
	 * Returns a set of the keys in this map
	 * @return SetInterface<mixed>
	 */
	public function getKeys();
	
	/**
	 * Returns a set of the values in this map
	 * @return SetInterface<mixed>
	 */
	public function getValues();
	
	/**
	 * Returns the first key associated with a given value (if any)
	 * 
	 * @param mixed $value
	 * @return mixed|null Returns null if no key is associated with the value
	 */
	public function keyOf($value);
	
	/**
	 * Returns all keys associated with a given value
	 * 
	 * @param mixed $value
	 * @return mixed[]
	 */
	public function keysOf($value);
	
	/**
	 * Removes a key from the map
	 * 
	 * @param mixed $key
	 * @return void
	 */
	public function remove($key);
	
	/**
	 * Associates a given key with a given value in the map
	 * 
	 * @param mixed $key
	 * @param mixed $value
	 * @return void
	 */
	public function set($key, $value);
	
	/**
	 * Associates multiple keys with multiple values in the map
	 * 
	 * @param Traversable $entries
	 * @return void
	 */
	public function setAll($entries);
	
	/**
	 * Returns this map in the form of an associative array (if possible)
	 * 
	 * @throws LogicException If operation is unsupported
	 * @return mixed[mixed]
	 */
	public function toArray();
	
	/**
	 * Sets the comparator used to sort this map
	 * 
	 * @param ComparatorInterface $comparator
	 * @return void
	 */
	public function setComparator(ComparatorInterface $comparator);
	
	/**
	 * Sets the predicate used to validate map keys
	 * 
	 * @param PredicateInterface $keyPredicate
	 * @return void
	 */
	public function setKeyPredicate(PredicateInterface $keyPredicate);
	
	/**
	 * Sets the predicate used to validate map values
	 * 
	 * @param PredicateInterface $valuePredicate
	 * @return void
	 */
	public function setValuePredicate(PredicateInterface $valuePredicate);
}